package com.zzyl.nursing.controller.member;

import com.zzyl.common.core.controller.BaseController;
import com.zzyl.common.core.domain.AjaxResult;
import com.zzyl.nursing.domain.FamilyMember;
import com.zzyl.nursing.dto.FamilyMemberAddDto;
import com.zzyl.nursing.dto.FamilyMemberMy;
import com.zzyl.nursing.dto.UserLoginRequestDto;
import com.zzyl.nursing.service.IFamilyMemberService;
import com.zzyl.nursing.vo.FamilyMemberLostByPageVo;
import com.zzyl.nursing.vo.LoginVo;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 老人家属Controller
 *
 * @author ruoyi
 * @date 2025-04-26
 */
@RestController
@RequestMapping("/member/user")
@Api(tags = "老人家属的接口")
public class FamilyMemberController extends BaseController {
    @Autowired
    private IFamilyMemberService familyMemberService;

    @PostMapping("/login")
    public AjaxResult login(@RequestBody UserLoginRequestDto dto) {
        LoginVo vo = familyMemberService.login(dto);
        return success(vo);
    }

    /**
     * 绑定老人家属
     *
     * @param dto 老人信息
     * @return
     */
    @PostMapping("/add")
    public AjaxResult add(@RequestBody FamilyMemberAddDto dto) {
        familyMemberService.add(dto);
        return success();
    }

    /**
     * 查询家人列表
     *
     * @return
     */
    @GetMapping("/my")
    public AjaxResult my() {
        List<FamilyMemberMy> list = familyMemberService.my();
        return success(list);
    }

    @GetMapping("/list-by-page")
    public AjaxResult listByPage() {
        List<FamilyMemberLostByPageVo> list = familyMemberService.listByPage();
        return success(list);
    }

    @GetMapping("/queryServiceProperties/{iotId}")
    public AjaxResult queryServiceProperties(@PathVariable String iotId) {
        return success(familyMemberService.queryServiceProperties(iotId));
    }

    @GetMapping("/queryDeviceDataListByDay")
    public AjaxResult queryDeviceDataListByDay(
            @RequestParam String iotId,
            @RequestParam String startTime,
            @RequestParam String endTime,
            @RequestParam String functionId) {
        return success(familyMemberService.queryDeviceDataListByDay(iotId, startTime, endTime, functionId));
    }
}
